package device

import (
	"jlpay-sdk-go/pkg/jlpay/core"
	"jlpay-sdk-go/pkg/jlpay/models/openmerch/device"
	"jlpay-sdk-go/pkg/jlpay/services"
)

// DeviceService 设备管理服务
type DeviceService struct {
	*services.BaseService
}

// NewDeviceService 创建设备管理服务实例
func NewDeviceService(config *core.Config) *DeviceService {
	return &DeviceService{
		BaseService: services.NewBaseService(config),
	}
}

// QueryUnionPayCode 查询银联码
func (s *DeviceService) QueryUnionPayCode(request *device.UnionPayCodeQueryRequest) (*device.UnionPayCodeQueryResponse, error) {
	response := device.NewUnionPayCodeQueryResponse()
	err := s.Post(request, response, "/open/merch/access/device/unionpay/query")
	return response, err
}

// AddUnionPayCode 添加银联码
func (s *DeviceService) AddUnionPayCode(request *device.UnionPayCodeAddRequest) (*device.UnionPayCodeAddResponse, error) {
	response := device.NewUnionPayCodeAddResponse()
	err := s.Post(request, response, "/open/merch/access/device/unionpay/add")
	return response, err
}

// ChangeDevice 变更设备
func (s *DeviceService) ChangeDevice(request *device.DeviceChangeRequest) (*device.DeviceChangeResponse, error) {
	response := device.NewDeviceChangeResponse()
	err := s.Post(request, response, "/open/merch/access/device/change")
	return response, err
}

// CancelDevice 撤销设备
func (s *DeviceService) CancelDevice(request *device.DeviceCancelRequest) (*device.DeviceCancelResponse, error) {
	response := device.NewDeviceCancelResponse()
	err := s.Post(request, response, "/open/merch/access/device/cancel")
	return response, err
}

// AddDevice 添加设备
func (s *DeviceService) AddDevice(request *device.DeviceAddRequest) (*device.DeviceAddResponse, error) {
	response := device.NewDeviceAddResponse()
	err := s.Post(request, response, "/open/merch/access/device/add")
	return response, err
}

// DeviceQuery 终端查询
func (s *DeviceService) DeviceQuery(request *device.DeviceQueryRequest) (*device.DeviceQueryResponse, error) {
	response := device.NewDeviceQueryResponse()
	err := s.Post(request, response, request.GetApiUrl())
	return response, err
}
